
<script>
    function asyncFn(){
        return new Promise((resolve,reject)=>{
            setTimeout(() => {
                resolve({state:200,msg:"登入成功"})
            }, 3000);
        })
    }
    function asyncFn2(){
        return new Promise((resolve,reject)=>{
            setTimeout(() => {
                resolve({state:300,msg:"数据获取成功"})
            }, 2000);
        })
    }
    // async function getData(){
    //     console.log(1);
    //     let data = await asyncFn()
    //     console.log(data);
    //     console.log(2);
    //     console.log(3);
    // }

    // getData()

    function* getData(){
        console.log(1);
        const val1 = yield asyncFn()
        console.log(val1);
        const val2 = yield asyncFn2()
        console.log(val2);
    }

    let it = getData()//返回generator迭代器
    //将指针指向第一个(yield)数据结构的成员
    it.next().value.then(res=>{
        // console.log(res);
        it.next(res).value.then(res=>{
            // console.log(res);
            it.next(res)
        })
    })

</script>